package dao

import (
	"fmt"
	"yun_image/entity"
	"yun_image/util"
)

var (
	webAccess []entity.WebAccess
)

func pullAllWebAccess() error {
	result := DB.Find(&webAccess)
	if result.Error != nil {
		fmt.Println(util.Red("webAccess同步失败！！"))
		return result.Error
	}
	fmt.Println(util.Green("webAccess同步成功"))
	return nil
}

func GetRouterNamesByRoleId(routerNames *[]string, roleId int) error {
	var names []string
	for _, value := range webAccess {
		if value.RoleId == roleId {
			names = append(names, value.RouterName)
		}
	}
	*routerNames = names
	return nil
}
